<%@ page import="com.party.core.model.system.TargetType" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="../../include/tag.jsp" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title> ${member.id == null ? '添加管理员' : '编辑资料'}</title>
    <%@include file="../../include/commonFile.jsp" %>
    <link rel="stylesheet" href="${ctx}/css/common/list.css">
    <link rel="stylesheet" href="${ctx}/css/ui/activity/publish_act.css">
    <style type="text/css">
        .cover-content .cover-img {
            width: 80px !important;
            height: 80px !important;
        }

        .layui-tab-brief > .layui-tab-title .layui-this {
            color: #e8473f !important;
        }

        .layui-tab-brief > .layui-tab-title .layui-this:after {
            border-bottom-color: #e8473f !important;
        }

        #mchForm .layui-form-item .layui-input-inline {
            width: 280px !important;
        }

        .forget-pwd-btn {
            color: #e8473f;
            margin-left: 20px;
        }

        .forget-pwd-btn:hover {
            color: #3b97d7;
        }
    </style>
</head>
<body>
<!--头部-->
<%@include file="../../include/header.jsp" %>
<div class="index-outside">
    <%@include file="../../include/sidebar.jsp" %>
    <!--内容-->
    <section>
        <div class="section-main">
            <%--<div class="c-time-list-header">
                <div class="r">
                    <a href="${ctx}/system/member/memberIndex.do" class="layui-btn layui-btn-radius layui-btn-danger"> <i class="iconfont icon-back btn-icon"></i>返回</a>
                </div>
                <div class="ovh">
                    <span class="title f20">账户中心&nbsp;&gt;&nbsp;资料编辑</span>
                </div>
            </div>--%>

            <input type="hidden" id="mobile" value="${member.mobile}"/>

            <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                <ul class="layui-tab-title" ${member.id == null ? 'style="display:none"' : ''}>
                    <%--<li><span class="title f20 ml5 mr5">服务升级</span></li>--%>
                    <li class="layui-this"><span class="title f20 ml5 mr5">资料编辑</span></li>
                    <c:if test="${partnerType == 4}">
                        <li><span class="title f20 ml5 mr5">提现账号</span></li>
                    </c:if>
                    <li><span class="title f20 ml5 mr5">修改密码</span></li>
                    <!-- 					<li><span class="title f20 ml5 mr5">绑定商户信息</span></li> -->
                    <c:if test="${empty member.mobile || member.mobile == ''}">
                        <li><span class="title f20 ml5 mr5">绑定手机</span></li>
                    </c:if>
                </ul>
                <div class="layui-tab-content">
                    <%--<div class="layui-tab-item"></div>--%>
                    <%--资料编辑--%>
                    <div class="layui-tab-item layui-show">
                        <!-- 正文请写在这里 -->
                        <div class="add-form-content">
                            <form id="myForm" class="layui-form mt20" method="post"
                                  action="${ctx}/member/group/saveAdmin.do">
                                <input type="hidden" name="id" value="${member.id}"/>
                                <input type="hidden" name="partnerId" value="${partnerId}"/>
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label">用户名<span class="f-verify-red">*</span></label>
                                        <div class="layui-input-inline">
                                            <c:choose>
                                                <c:when test="${empty member.id}">
                                                    <input class="layui-input" name="username" lay-verify="username"
                                                           placeholder="用户名" value='${member.username}'/>
                                                </c:when>
                                                <c:when test="${not empty member.id}">
                                                    <c:if test="${empty member.username}">
                                                        <input class="layui-input" name="username" lay-verify="username"
                                                               placeholder="用户名" value='${member.username}'/>
                                                    </c:if>
                                                    <c:if test="${not empty member.username}">
                                                        <div style="height: 38px; line-height: 38px;">${member.username}</div>
                                                        <input type="hidden" name="username"
                                                               value='${member.username}'/>
                                                    </c:if>
                                                </c:when>
                                            </c:choose>
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label">昵称<span class="f-verify-red">*</span></label>
                                        <div class="layui-input-inline">
                                            <input class="layui-input" name="realname" lay-verify="realname"
                                                   placeholder="昵称" value='${member.realname}'/>
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label">真实姓名<span class="f-verify-red">*</span></label>
                                        <div class="layui-input-inline">
                                            <input class="layui-input" name="fullname" placeholder="真实姓名"
                                                   lay-verify="fullname"
                                                   value='${member.fullname}'/>
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">头像</label>
                                    <div class="cover-content">
                                        <input type="hidden" name="logo" id="pic" lay-verify="pic"
                                               value="${(member.logo == null || empty member.logo) ? 'http://txzapp-10052192.image.myqcloud.com/1490783498894':member.logo}"/>
                                        <c:if test="${member == null || empty member.logo}">
                                        <span id="cover-img" class="round-img"
                                              style="background-image:url(http://txzapp-10052192.image.myqcloud.com/1490783498894)"></span>
                                        </c:if>
                                        <c:if test="${member != null && not empty member.logo}">
                                        <span id="cover-img" class="round-img"
                                              style="background-image:url('${member.logo}')"></span>
                                        </c:if>
                                        <a class="layui-btn layui-btn-danger" id="sel_pic_img">+添加头像</a>
                                    </div>
                                </div>
                                <div class="layui-form-item" ${member.mobile != '' && not empty member.mobile ? '' : 'style="display:none"'}>
                                    <div class="layui-inline">
                                        <label class="layui-form-label">手机号</label>
                                        <div class="layui-input-inline">
                                            <div style="height: 38px; line-height: 38px;">${member.mobile}</div>
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label">职位</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="jobTitle" autocomplete="off" class="layui-input"
                                                   value="${member.jobTitle}">
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <a href="javascript:void(0)" class="layui-btn layui-btn-danger" lay-submit
                                           lay-filter="infoForm">立即提交</a>
                                        <button type="reset" class="layui-btn layui-btn-primary"
                                                onclick="cancelFunction()">取消
                                        </button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                    <%--修改登录密码--%>
                    <div class="layui-tab-item">
                        <div class="add-form-content">
                            <form id="pwdForm" class="layui-form mt20" method="post"
                                  action="${ctx}/system/member/updatePwd.do">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label"></label>
                                        <div class="layui-input-inline" style="width: 240px">
                                            <span style="color: #aaa">密码只能输入6-20位字母或数字</span>
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label">原密码<span class="f-verify-red">*</span></label>
                                        <div class="layui-input-inline">
                                            <input type="password" class="layui-input" name="oldPassword"
                                                   lay-verify="oldPassword" placeholder="原密码"/>
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label">新密码<span class="f-verify-red">*</span></label>
                                        <div class="layui-input-inline">
                                            <input type="password" class="layui-input" name="password"
                                                   lay-verify="password" placeholder="新密码"/>
                                            <input type="hidden" name="id" value="${member.id}"/>
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label">确认密码<span class="f-verify-red">*</span></label>
                                        <div class="layui-input-inline">
                                            <input type="password" class="layui-input" name="repassword"
                                                   lay-verify="repassword" placeholder="再次确认密码"/>
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <a href="javascript:void(0)" class="layui-btn layui-btn-danger" lay-submit
                                           lay-filter="pwdForm">立即修改</a>
                                        <button type="reset" class="layui-btn layui-btn-primary"
                                                onclick="cancelFunction()">取消
                                        </button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                    <%--绑定手机号--%>
                    <c:if test="${empty member.mobile || member.mobile == ''}">
                        <div class="layui-tab-item">
                            <div class="add-form-content">
                                <form id="bdPhoneForm" class="layui-form mt20" method="post"
                                      action="${ctx}/system/member/bindPhone.do">
                                    <input type="hidden" name="id" value="${member.id}"/>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">手机号<span class="f-verify-red">*</span></label>
                                        <div class="layui-input-block login-input" style="width: 300px;">
                                            <input type="text" name="phone" id="phone1" lay-verify="mobile" autocomplete="off" maxlength="11"
                                                   placeholder="请输入手机号码" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">图片验证码<span class="f-verify-red">*</span></label>
                                        <div class="layui-input-block login-input" style="width: 300px;">
                                            <input type="text" id="imgCode1" lay-verify="imgCode" autocomplete="off"
                                                   placeholder="请输入右侧图片内容" class="layui-input l"
                                                   style="width: calc(100% - 120px); margin-right: 10px;">
                                            <img width="100" src="" alt="" id="code_img1"
                                                 style="height: 36px; width: 108px;">
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">手机验证码<span class="f-verify-red">*</span></label>
                                        <div class="layui-input-block login-input" style="width: 300px;">
                                            <input type="text" name="verifyCode" id="verify_code1"
                                                   lay-verify="verifyCode" placeholder="请输入手机验证码" class="layui-input l"
                                                   style="width: calc(100% - 120px); margin-right: 10px;">
                                            <button id="code1" type="button" class="layui-btn layui-btn-primary"
                                                    style="width: 110px!important">发送验证码
                                            </button>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <div class="layui-input-block">
                                            <button class="layui-btn layui-btn-danger" lay-submit
                                                    lay-filter="bdPhoneForm">绑定
                                            </button>
                                            <button type="reset" class="layui-btn layui-btn-primary"
                                                    onclick="cancelFunction()">取消
                                            </button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </c:if>
                </div>
            </div><!--底部-->
        </div>
        <%@include file="../../include/footer.jsp" %>
    </section>
</div>
<script type="text/javascript" src="${ctx}/script/common/v_code.js"></script>
<script>
    $(function () {
        layui.use(['form', 'laydate', 'element'], function () {
            var form = layui.form, laydate = layui.laydate, element = layui.element;

            element.on('tab', function (data) {

            });

            //自定义验证规则
            form.verify({
                username: function (value) {
                    if (!value) {
                        return '用户名不能为空';
                    }
                    if (value != "") {
                        if (!util.checkEmail(value) && !util.checkUserName(value)) {
                            return "用户名可以是邮箱或只能以字母开头、可带数字、@和下划线";
                        } else {
                            var isRepeat = txz.checkGroupIsUnique('username', value, '${member.id}');
                            if (undefined == isRepeat) {
                                return "验证用户名异常";
                            } else if (isRepeat) {
                                return "用户名已存在";
                            }
                        }
                    }
                },
                fullname: function (value) {
                    if (value == "") {
                        return '请输入真实姓名';
                    }
                },
                realname: function (value) {
                    if (value == "") {
                        return '请输入昵称';
                    }
                },
                pic: function (value) {
                    if (value == "") {
                        return "请上传头像";
                    }
                },
                mobile: function (value) {
                    if (value == "") {
                        return "请输入手机号码";
                    } else if (!util.checkMobile(value)) {
                        return "请输入正确格式的手机号码";
                    } else if (value != "" && util.checkMobile(value)) {
                        var isRepeat = txz.checkGroupIsUnique('mobile', value, '${member.id}', 2);
                        if (undefined == isRepeat) {
                            return "验证手机号异常";
                        } else if (isRepeat) {
                            return "手机号已存在";
                        }
                    }
                },
                oldPassword: function (value) {
                    if (value == "") {
                        return "原密码不能为空";
                    } else {
                        var isRepeat = ajaxSubmit({
                            password: value,
                            userId: '${member.id}'
                        }, "${ctx}/system/member/checkPassword.do");
                        if (isRepeat) {
                            return "原密码错误";
                        }
                    }
                },
                password: function (value) {
                    if (value == "") {
                        return "密码不能为空";
                    } else if (!util.checkPassword(value)) {
                        return "密码格式不正确";
                    }
                },
                repassword: function (value) {
                    var pwd = $("#pwdForm [name=password]").val();
                    if (value == "") {
                        return "确认密码不能为空";
                    } else if (!util.checkPassword(value)) {
                        return "确认密码格式不正确";
                    } else if (pwd != value) {
                        return "确认密码与新密码不匹配";
                    }
                },
                verifyCode: function (value) {
                    if (value == "") {
                        return "请输入手机验证码";
                    }
                },
                imgCode: function (value) {
                    if (value == "") {
                        return "请输入右侧图片内容";
                    }
                }
            });

            function ajaxSubmit(data, url) {
                var isRepeat = false;
                $.ajax({
                    type: 'POST',
                    async: false, // 使用同步的方法
                    data: data,
                    dataType: 'json',
                    success: function (result) {
                        isRepeat = !result;
                    },
                    url: url
                });
                return isRepeat;
            }

            //监听提交 编辑资料
            form.on('submit(infoForm)', function (data) {
                txz.submitObject(data.elem, function (callBack) {
                    var action = $("#myForm").attr("action");
                    $.post(action, $('#myForm').serialize(), function (res) {
                        typeof callBack === 'function' && callBack();
                        if (res.success) {
                            util.layerMsgSuccess(res.description, function () {
                                window.location.href = document.referrer;
                                // window.history.back(-1);
                                // alert(document.referrer);
                            })
                        } else {
                            util.layerMsgError("资料编辑失败")
                        }
                    })
                });
                return false;
            });
            //监听提交 修改密码
            form.on('submit(pwdForm)', function (data) {
                txz.submitObject(data.elem, function (callBack) {
                    var action = $("#pwdForm").attr("action");
                    $.post(action, $('#pwdForm').serialize(), function (res) {
                        typeof callBack === 'function' && callBack();
                        if (res.success) {
                            util.layerMsgSuccess("密码修改成功", function () {
                                window.location.reload();
                            })
                        } else {
                            util.layerMsgError("密码修改失败")
                        }
                    })
                });
                return false;
            });

            //监听提交 绑定手机
            form.on('submit(bdPhoneForm)', function (data) {
                var newData = data;
                Vcode.checkCode(cb(newData));

                function cb(data) {
                    txz.submitObject(data.elem, function (callBack) {
                        var action = $("#bdPhoneForm").attr("action");
                        $.post(action, $('#bdPhoneForm').serialize(), function (res) {
                            typeof callBack === 'function' && callBack();
                            if (res.success) {
                                util.layerMsgSuccess("手机绑定成功", function () {
                                    window.location.reload();
                                })
                            } else {
                                util.layerMsgError(res.description || "手机绑定失败")
                            }
                        });
                    })
                }

                return false;
            });
        });
        $('#sel_pic_img').click(function () {
            txz.openSelImg({
                min: 1,
                max: 1,
                info: '建议尺寸：120x120',
                type: '<%=TargetType.LOGO.getCode()%>',
                cb: function (imgs) {
                    $('#cover-img').css('background-image', 'url(' + imgs[0].path + ')');
                    $('#pic').val(imgs[0].path);
                }
            })
        });

        $("#phone1").bind("input propertychang",function(event){
            var viewName = this.value;
            if (viewName && viewName.length == 11) {
                $('#code_img1').attr('src', '${ctx}/verification/mobile/crimg/' + viewName + '.do');
                $('#code_img1').css("border", "1px solid #e6e6e6");

                Vcode.params.vCodeImg = '#code_img1';
                Vcode.params.vImgCode = '#imgCode1';
                Vcode.params.vGetCodeBtn = '#code1';
                Vcode.params.vPhone = '#phone1';
                Vcode.params.vCode = '#verify_code1';
                Vcode.params.vMemberType = 2;

                Vcode.addEvent();
            }
        });

        $('#cancel_btn,.f-def-dialog .close-icon').click(function () {
            $('#forget_pwd_dialog').fadeOut();
            Vcode.unBind();
        });

        $('#forget_pwd_btn').click(function () {
            var mobile = $('#mobile').val();
            if (!mobile) {
                util.layerAlertError("请先绑定手机")
                return;
            }
            $("[name=loginName]").val(mobile);

            $('#forget_pwd_dialog').fadeIn();

            $('#code_img').attr('src', '${ctx}/verification/mobile/crimg/' + mobile + '.do');
            $('#code_img').css("border", "1px solid #e6e6e6");
            $('#img_code_li').show();

            Vcode.params.vCodeImg = '#code_img';
            Vcode.params.vImgCode = '#imgCode';
            Vcode.params.vGetCodeBtn = '#code';
            Vcode.params.vPhone = '#phone';
            Vcode.params.vCode = '#verify_code';
            Vcode.params.vMemberType = 2;

            Vcode.addEvent();
        });

    });

    function cancelFunction() {
        if ('${from}' == 'manager') {
            location.href = "${ctx}/member/group/adminList.do";
        } else {
            location.href = "${ctx}/system/member/memberIndex.do";
        }
    }
</script>
<script type="text/javascript">
    if ('${from}' == 'manager') {
        txz.initHeader({
            nav: [{
                name: ''
            }, {
                name: '${partnerName}'
            },{
                name: '${member.id == null ? '添加管理员' : '编辑资料'}',
                curr: true
            }],
            btns: [{
                name: '返回',
                icon: 'back',
                href: '${ctx}/member/group/adminList.do'
            }]
        });
    } else {
        txz.initHeader({
            nav: [{
                name: '账户中心'
            }, {
                name: '资料编辑',
                curr: true
            }],
            btns: [{
                name: '返回',
                icon: 'back',
                href: '${ctx}/system/member/memberIndex.do'
            }]
        });
    }
</script>
</body>
</html>